<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  template="../WEB-INF/template/template.xhtml"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  xmlns:h="http://java.sun.com/jsf/html">

  <f:metadata>
    <f:event type="preRenderView" listener="#{identity.checkRole('admin')}"/>
    <f:viewParam name="id" value="#{roleAssignmentRuleAction.id}" />
  </f:metadata>

  <ui:define
    name="page_title">#{msgs['jsf.rolerules.EditRoleAssignmentRule']}</ui:define>
  <ui:define name="center_content">

    <div class="g--centered">
      <div class="g__item w--1-2-m w--3-8-l w--1-3 l--push-bottom-1">
        <p class="txt--meta l--push-all-0">
          <a href="/admin/home">
            #{msgs['jsf.Administration']}
          </a>
          <i class="i i--arrow-right"></i>
          <h:link outcome="/admin/rolerules.xhtml"
            value="#{msgs['jsf.RoleAssignmentRules']}"/>
        </p>

        <h1 class="l--push-all-0">#{msgs['jsf.rolerules.EditRoleAssignmentRule']}</h1>
        <h:form id="role-rule-form">
          <div class="form__item l--push-top-1">
            <h:outputLabel>#{msgs['jsf.rolerules.PolicyName']}
            <span class="txt--meta"><i class="i i--info"
              title="#{msgs['jsf.rolerules.PolicyName.tooltip']}"></i>
            </span>
            </h:outputLabel>
            <zanata:decorate id="policyName" componentId="policyNameField">
              <h:selectOneMenu id="policyName"
                value="#{roleAssignmentRuleAction.instance.policyName}">
                <f:selectItem noSelectionOption="true" itemLabel="" />
                <f:selectItems value="#{roleAssignmentRuleAction.availablePolicyNames}"
                  var="policy" itemLabel="#{policy}"
                  />
              </h:selectOneMenu>
            </zanata:decorate>
          </div>

          <div class="form__item l--push-top-1">
            <h:outputLabel
              for="identityPattern">#{msgs['jsf.rolerules.IdentityPattern']}
              <span class="txt--meta"><i class="i i--info"
                title="#{msgs['jsf.rolerules.IdentityPattern.tooltip']}"></i>
              </span>
            </h:outputLabel>
            <zanata:decorate id="identityPattern" componentId="identityPatternField">
              <h:inputText id="identityPattern"
                value="#{roleAssignmentRuleAction.instance.identityRegExp}"/>
            </zanata:decorate>
          </div>

          <div class="form__item l--push-top-1">
            <h:outputLabel for="identityPattern">#{msgs['jsf.rolerules.RoleToAssign']}
            <span class="txt--meta"><i class="i i--info"
              title="#{msgs['jsf.rolerules.RoleToAssign.tooltip']}"></i>
            </span>
            </h:outputLabel>
            <zanata:decorate id="role" componentId="roleField">
              <h:selectOneMenu id="roles"
                value="#{roleAssignmentRuleAction.roleToAssign}">
                <f:selectItems value="#{identityManager.listGrantableRoles()}"
                  var="role" itemLabel="#{role}"/>
              </h:selectOneMenu>
            </zanata:decorate>
          </div>

          <h:commandButton id="save" styleClass="button button--primary"
            value="#{msgs['jsf.Save']}"
            action="#{roleAssignmentRuleAction.persist}"
            rendered="#{!roleAssignmentRuleAction.managed}"/>

          <h:commandButton id="update" styleClass="button button--primary"
            value="#{msgs['jsf.Update']}"
            action="#{roleAssignmentRuleAction.update}"
            rendered="#{roleAssignmentRuleAction.managed}"/>

          <h:button id="cancel" styleClass="button button--link l--push-left-half"
            value="#{msgs['jsf.Cancel']}"
            outcome="/admin/rolerules.xhtml"/>
        </h:form>

      </div>
    </div>
  </ui:define>

</ui:composition>
